package com.cyandpos.pad.report;

import android.content.Context;

import com.changyi.device.printer.PrintManagerLib;
import com.cyandpos.pad.common.commondata.ErpCommonData;
import com.cyandpos.pad.common.ticketformat.TicketFormat;
import com.cyandpos.pad.login.configs.GetConfigs;
import com.cyandpos.pad.posdata.ClassNewspaperAndDaily;
import com.cyandpos.pad.posdata.Payment;
import com.cyandpos.pad.posdata.ReportGroup;
import com.cyandpos.pad.posdata.ReportPay;
import com.cyandpos.pad.utils.CommonUtils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import static com.cyandpos.pad.common.ticketformat.TicketFormat.makeStr;
 
/**
 * Created by Administrator on 2017/05/08.
 */

public class ReportPrint {

    private List<Payment> paymentList;
    private int style;
    private int saleMoney, saleNo, backMoney, backNo;
    private Context context;
    private ClassNewspaperAndDaily daily;

    public ReportPrint(Context context,ClassNewspaperAndDaily daily, int style){
        this.context = context;
        this.daily=daily;
        this.style = style;
    }

    public void doPrint() {
        String title="";
        if (style == 1) {
            title="本班日报";
        } else {
            title="收银日报";
        }
        for(int i = 0; i< GetConfigs.ticketPrintCount(); i++) {
            PrintManagerLib.initPrinter(context, CommonUtils.getSystemModel())
                    .initDevice()
                    .printTitle(title)
                    .printList(printContext());
        }

    }


    public List<String> printContext() {
        List<String> list = new ArrayList<>();
        if (style == 1) {
            list.add("收银员:" + ErpCommonData.loadConfig.getCashierName());
        }
        list.add("收款台:" + ErpCommonData.loadConfig.getCashierDeptName());
        list.add("打印时间:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime()));
        list.add("交易次数:" + daily.getCount_sale());
        list.add("交易金额:" + daily.getTotal_sale());
        list.add("退货次数:" + daily.getCount_back());
        list.add("退货金额:" + daily.getTotal_back());
        list.add("部门代码    部门名称     金额");
        for (ReportGroup reportGroup: daily.getReportGroupList()){
            list.add((makeStr(reportGroup.getDeptCode(),11,false)+makeStr(reportGroup.getDeptName(),9,false)+makeStr( reportGroup.getAmount(),9,false)));
        }

        list.add(TicketFormat.getStr());
        list.add("付款方式    金额     溢余");
        for (ReportPay reportPay:daily.getReportPayList()){
            list.add((makeStr(reportPay.getName(),12,false)+makeStr(reportPay.getAmount(),9,false)+makeStr(reportPay.getAmount_yy(),9,false)));
        }
        list.add("");
        list.add("");
        list.add("");
        list.add("");
        return list;
    }
}
